home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16592 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  980 b 

  1. Path: mail2news.demon.co.uk!txwang
  2. From: Wang TianXing <gztxwang@public1.guangzhou.gd.cn>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: fastest code
  5. Date: Thu, 11 Apr 1996 13:03:34 GMT
  6. Message-ID: <199604111303.VAA11095@public1.guangzhou.gd.cn>
  7. X-NNTP-Posting-Host: txwang
  8. X-Newsreader: Forte Free Agent 1.0.82
  9. X-Mail2News-Path: public1.guangzhou.gd.cn!txwang
  10.  
  11. On Tue, 09 Apr 1996 15:28:22 -0400, Sean Palmer <sean@delta.com>
  12. wrote:
  13.  
  14. | Being dumb aside, if the (fictitious bad) compiler, for this C++ code:
  15.  
  16. | void test(int& x) {
  17. |   if (!(x==0))
  18. |     x=x+1;
  19. |   }
  20.  
  21. | generates the following x86 asm code:
  22.  
  23.   [ lots of code deleted ]
  24.  
  25. | while another compiler generates this code:
  26.  
  27. | test@i:
  28. |   mov ebx,[eax]
  29. |   test ebx,ebx
  30. |   jnz @@loc1
  31. |   inc dword ptr [eax]
  32. | @@loc1:
  33. |   ret  
  34.  
  35. | which would you rather call in a 10000-iteration loop?
  36.  
  37. I'd prefer a compiler that could generate:
  38.  
  39. test@i:
  40.   cmp [eax], 1
  41.   sbb [eax], -1
  42.   ret
  43.  
  44. Which compiler does this?  :)
  45.  
  46.  
  47. --
  48. Wang TianXing
  49.  
  50.  
  51.